package smcms.service.cloudstore.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smcms.commons.api.entity.result.CommonsResult;
import smcms.service.cloudstore.entity.CloudStoreReq;
import smcms.service.cloudstore.entity.CloudStoreResp;
import smcms.service.cloudstore.entity.StaffInfoReq;

import smcms.service.cloudstore.feignservices.SsoFeignService;
import smcms.service.cloudstore.service.StoreManagerService;

import java.util.List;

@RestController
@RequestMapping("/StoreManagerController")
public class StoreManagerController {

    @Autowired
    private StoreManagerService storeManagerService;

    @Autowired
    private CommonsResult commonsResult;

    @Autowired
    private SsoFeignService ssoFeignService;

    /**
     * 新增小店
     * @param cloudStoreReq
     * @return
     */
    @PostMapping("/addCloudStore")
    public CommonsResult addCloudStore(@RequestBody CloudStoreReq cloudStoreReq){
        return storeManagerService.addCloudStoreInfo(cloudStoreReq);
    }

    @PostMapping("/queryCloudStore")
    public CommonsResult queryCloudStore(@RequestBody CloudStoreReq cloudStoreReq) {
        List<CloudStoreResp> cloudStoreRespList = storeManagerService.queryCloudStoreList(cloudStoreReq);

        return commonsResult.success(cloudStoreRespList);
    }

    @PostMapping("/delCloudStore")
    public CommonsResult delCloudStore(@RequestBody CloudStoreReq cloudStoreReq){
        CommonsResult commonsResult = storeManagerService.delCloudStore(cloudStoreReq);
        return commonsResult;
    }
    @PostMapping("/getStaffListByRole")
    @PreAuthorize(value = "hasAuthority('getStaffListByRole')")
    public CommonsResult getStaffListByRole(@RequestBody StaffInfoReq staffInfoReq){
        CommonsResult commonsResult = ssoFeignService.getStaffList(staffInfoReq);
        return commonsResult;
    }
}
